package com.spaceobj.project.service.impl;

import cn.dev33.satoken.util.SaResult;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spaceobj.project.mapper.SysSourceTypeMapper;
import com.spaceobj.project.pojo.SysSourceType;
import com.spaceobj.project.service.SysSourceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hrzhang
 */
@Service
public class SysSourceTypeServiceImpl extends ServiceImpl<SysSourceTypeMapper, SysSourceType>
    implements SysSourceTypeService {

  @Autowired private SysSourceTypeMapper sysSourceTypeMapper;

  @Override
  public SaResult add(SysSourceType sysSourceType) {
    int result = sysSourceTypeMapper.insert(sysSourceType);
    if (result == 0) {
      return SaResult.error();
    }
    return SaResult.ok();
  }

  @Override
  public SaResult update(SysSourceType sysSourceType) {
    int result = sysSourceTypeMapper.updateById(sysSourceType);
    if (result == 0) {
      return SaResult.error();
    }
    return SaResult.ok();
  }

  @Override
  public SaResult list(SysSourceType sysSourceType) {
    QueryWrapper<SysSourceType> queryWrap = new QueryWrapper();
    List<SysSourceType> selectList = sysSourceTypeMapper.selectList(queryWrap);
    return SaResult.ok().setData(selectList);
  }

  @Override
  public SaResult findById(long id) {
    SysSourceType sysSourceType = sysSourceTypeMapper.selectById(id);
    return SaResult.ok().setData(sysSourceType);
  }
}
